cmake_minimum_required(VERSION 3.14)

project(YCLocation VERSION 0.1 LANGUAGES CXX)

set(CMAKE_INCLUDE_CURRENT_DIR ON)

set(CMAKE_AUTOUIC ON)
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTORCC ON)

set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

# 设置Qt路径
set(CMAKE_PREFIX_PATH "/opt/Qt5.12.12/5.12.12/gcc_64/lib/cmake")

# 查找Qt模块
find_package(Qt5 REQUIRED COMPONENTS Core Widgets Quick Location Positioning Qml Sql Network)

# 设置包含目录
include_directories(
    ${CMAKE_CURRENT_SOURCE_DIR}
    ${CMAKE_CURRENT_SOURCE_DIR}/QtLocationPlugin
)

# 添加Qt Location插件子目录
add_subdirectory(QtLocationPlugin)

# 收集源文件 - 移除不需要的文件
set(SOURCES
    main.cpp
    QGCFileDownload.cc
    QmlObjectListModel.cc
    # 移除重复的QGCMapEngineManager.cc，因为它已经在QtLocationPlugin中编译
)

# 收集头文件
set(HEADERS
    QGCFileDownload.h
    QmlObjectListModel.h
    math1.h
    # 移除重复的QGCMapEngineManager.h
)

# 创建可执行文件
add_executable(${PROJECT_NAME}
    ${SOURCES}
    ${HEADERS}
    qml.qrc
)

target_link_libraries(YCLocation PRIVATE 
    Qt5::Core
    Qt5::Widgets
    Qt5::Quick
    Qt5::Location
    Qt5::Positioning
    Qt5::Qml
    Qt5::Sql
    Qt5::Network
    QtLocationPlugin
)

# 设置目标属性
set_target_properties(${PROJECT_NAME} PROPERTIES
    AUTOMOC ON
    AUTORCC ON
    AUTOUIC ON
)

# 设置Qt模块包含目录
target_include_directories(${PROJECT_NAME} PRIVATE ${Qt5Location_PRIVATE_INCLUDE_DIRS})
target_include_directories(${PROJECT_NAME} PRIVATE ${Qt5Positioning_PRIVATE_INCLUDE_DIRS})
